/*
 * Created on 07-feb-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.juanfrivaldes.cio2005.gestion;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * @author root
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class GestionConfirmacionesAction extends GestionAction {

	private static Log log = LogFactory
			.getLog(GestionConfirmacionesAction.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.juanfrivaldes.cio2005.web.BaseAction#protectedExecute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	protected ActionForward protectedExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		List resumenes=null;
		List finales=null;
		GestionPonenciasFiltradasForm ponenciasForm = (GestionPonenciasFiltradasForm) form;
		
		//limpiamos las variables de sesion por si acaso
		request.getSession(false).setAttribute("nResumenesCon",null);
		request.getSession(false).setAttribute("nFinalesCon",null);
		request.getSession(false).setAttribute("resumenesCon",null);
		request.getSession(false).setAttribute("finalesCon",null);

		if (ponenciasForm == null || ponenciasForm.getCategoria() == null) {
			resumenes = this.getCio2005().getPonenciasConfirmables();
			finales=this.getCio2005().getFinalesConfirmables();
		} else {
			 
			 log.trace("Se piden ponencias sin confirmacion para categoria "
					+ ponenciasForm.getCategoria());
			resumenes = this.getCio2005().getPonenciasConfirmablesByCategoria(
					ponenciasForm.getCategoria());
			finales=this.getCio2005().getPonenciasFinalesConfirmablesByCategoria(
					ponenciasForm.getCategoria());
		}
		
		if (resumenes != null) {
			log.trace("Recuperadas " + resumenes.size() + " resumenes confirmables");
			request.getSession(false).setAttribute("nResumenesCon", new Integer(resumenes.size()));
			if(resumenes.size()>0)
				request.getSession(false).setAttribute("resumenesCon", resumenes);
		} else {
			request.setAttribute("nResumenesCon", new Integer(0));
		}
		
		if (finales != null) {
			log.trace("Recuperadas " + finales.size() + " finales confirmables");
			request.getSession(false).setAttribute("nFinalesCon", new Integer(finales.size()));
			if (finales.size()>0)
				request.getSession(false).setAttribute("finalesCon", finales);
		} else {
			request.setAttribute("nFinalesCon", new Integer(0));
		}

		return mapping.findForward("success");
	}

}
